package com.itheima.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 包名:com.itheima.interceptor
 *
 * @author Leevi
 * 日期2020-08-15  10:57
 * 1. 自定义一个拦截器实现HandlerInterceptor接口
 * 2. 重写它的方法
 *    preHandle：在执行处理器方法之前执行
 *    postHandle：执行处理器方法之后执行
 *    afterCompletion：这次请求完成之后执行
 * 3. 在springmvc的配置文件中，配置拦截器
 */
public class PermissionInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进行权限校验....");
        //返回true表示放行，返回false表示拦截
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("权限校验的posthandle方法执行了...");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("权限校验的afterCompletion方法执行了...");
    }
}
